<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/css/bootstrap.min.css">
    <style>
        body {
            background-size: cover;
            background-position: center;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h3 class="text-center">用户登录</h3>
    <form id="loginForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" placeholder="请输入用户名">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" placeholder="请输入密码">
        </div>
        <button type="submit" class="btn btn-primary btn-block">登录</button>
    </form>
    <div id="loginError" class="text-danger mt-2 text-center"></div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    function setBackgroundImage() {
        const isMobile = /Mobi|Android|iPhone/i.test(navigator.userAgent);
        document.body.style.backgroundImage = isMobile
            ? "url('/bg-login-mobile.jpg')"  // 手机端背景图片
            : "url('/bg-login-desktop.jpg')"; // 电脑端背景图片
    }

    setBackgroundImage();

    $("#loginForm").on("submit", function (e) {
        e.preventDefault();

        const username = $("#username").val();
        const password = $("#password").val();

        $.ajax({
            url: '/login',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({ username, password }),
            success: function () {
                window.location.href = '/userList_wsq_and_hxh_yiqikaifa_bunengbeicaidao_suijishu_19283';
            },
            error: function () {
                $("#loginError").text("用户名或密码错误，请重试。");
            }
        });
    });
</script>
</body>
</html>
